local skel = fk.CreateSkill {
  name = "emo__seyou",
  tags = {Skill.Compulsory},
}

Fk:loadTranslationTable{
  ["emo__seyou"] = "色诱",
  [":emo__seyou"] = "锁定技，每轮开始时，你变形成随机女性武将，然后获得此武将随机一个无技能标签的技能，然后获得随机一名男性角色的随机两张牌。",
}

skel:addEffect(fk.RoundStart, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    -- 更新武将库
    local tag = room:getTag("emo__seyou_general")
    if tag == nil then
      tag = {}
      for _, g in ipairs(Fk:getAllGenerals()) do
        if g.gender == General.Female then
          local skills = table.filter(g:getSkillNameList(), function(s)
            local skill = Fk.skills[s]
            return skill and skill:getSkeleton() and #skill:getSkeleton().tags == 0
          end)
          if #skills > 0 then
            table.insert(tag, {g.name, skills})
          end
        end
      end
      room:setTag("emo__seyou_general", tag)
    end
    local copy = table.simpleClone(tag)
    local exists = {}
    for _, p in ipairs(room.players) do
      table.insert(exists, p.general)
      if p.deputyGeneral ~= "" then
        table.insert(exists, p.deputyGeneral)
      end
    end
    -- 随机找一个能获得技能的武将
    local general, skill
    while #copy > 0 do
      local list = table.remove(copy, math.random(#copy))
      local g, skills = table.unpack(list)
      if not table.contains(exists, g) then
        skills = table.filter(skills, function(s) return not player:hasSkill(s, true) end)
        if #skills > 0 then
          general = g
          skill = table.random(skills)
          break
        end
      end
    end
    if general == nil then return end
    if player.deputyGeneral == "moesp__xuanwomingzi" or player.tag["emo__seyou_deputy"] then
      player.tag["emo__seyou_deputy"] = true -- 记录自己原位置在副将
      room:setDeputyGeneral(player, general)
    else
      room:setPlayerGeneral(player, general, true)
    end
    room:handleAddLoseSkills(player, skill)
    -- 偷随机男性2张牌
    local targets = table.filter(room:getOtherPlayers(player), function (p)
      return not p:isNude() and p:isMale()
    end)
    if #targets == 0 then return false end
    local to = table.random(targets)
    room:doIndicate(player, {to})
    room:moveCardTo(table.random(to:getCardIds("he"), 2), Card.PlayerHand, player, fk.ReasonPrey, self.name, nil, false, player)
  end,
})

return skel
